package com.hpf.lease.common.config;

import com.hpf.lease.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionConfig {
    @ExceptionHandler(value = CommonException.class)
    public Result<String> exception(CommonException e){
        if (e.getThrowable() != null){
            log.error(ExceptionUtils.getStackTrace(e.getThrowable()));
        }
        return Result.build(e.getCode(),e.getMessage(),false,null);
    }
    @ExceptionHandler(value = Exception.class)
    public Result<String> exception(Exception e){
        log.error(ExceptionUtils.getStackTrace(e));
        return Result.fail();
    }
}
